﻿<%@ Page Language="C#" AutoEventWireup="true" Inherits="ShopOnline.Cart" MasterPageFile="~/ProductMaster.master"
    Theme="ShopOnline" CodeBehind="Cart.aspx.cs" %>

<%@ Register Src="~/Controls/ShopOnline/ShoppingCart.ascx" TagName="ShoppingCart"
    TagPrefix="cc" %>
<asp:Content runat="server" ID="cSearch" ContentPlaceHolderID="ContentPlaceHolder1">
    <script type="text/javascript" src="scripts/jquery.smartWizard-2.0.js"></script>
    <link href="css/smart_wizard.css" rel="stylesheet" type="text/css" />
    <link href="css/BusinessCard.css" rel="stylesheet" type="text/css" />
    <link href="css/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" />
    <style>
        .stepContainer
        {
            height: 500px !important;
        }
    </style>
    <script type="text/javascript">
        var item_number = <%= ShopOnline.BasePage.SelectedItems.RowCount %>;

        function leaveAStepCallback(obj) {
                var step_num = obj.attr('rel'); // get the current step number
                return validateStep(step_num);
                if (step_num == 2)
                    confirmUserInfo();
        }

        function validateStep(step_num) {
                
            if(step_num == 1 && item_number <= 0){
                showErrorAlert('Validation', 'No item to purchase!');
                return false;
            }

            if(step_num == 2){
                if($('#<%=txtName.ClientID %>').val() == ''){
                    showErrorAlert('Validation', 'Customer name required!');
                    return false;
                }

                if($('#<%=txtPhone.ClientID %>').val() == ''){
                    showErrorAlert('Validation', 'Customer phone number required!');
                    return false;
                }

                if($('#<%=txtAddress.ClientID %>').val() == ''){
                    showErrorAlert('Validation', 'Customer address required!');
                    return false;
                }

                if($('#<%=txtShipTo.ClientID %>').val() == ''){
                    showErrorAlert('Validation', 'Shipping address required!');
                    return false;
                }

                if($('#<%=txtEmail.ClientID %>').val() == ''){
                    showErrorAlert('Validation', 'Customer email required!');
                    return false;
                }

                confirmUserInfo();
            }

            return true;
        }

        function confirmUserInfo() {
            $('#<%=lblConfirmName.ClientID %>').html($('#<%=txtName.ClientID %>').val());
            $('#<%=lblConfirmPhone.ClientID %>').html($('#<%=txtPhone.ClientID %>').val());
            $('#<%=lblConfirmAddress.ClientID %>').html($('#<%=txtAddress.ClientID %>').val());
            $('#<%=lblConfirmShipTo.ClientID %>').html($('#<%=txtShipTo.ClientID %>').val());
            $('#<%=lblConfirmShipDate.ClientID %>').html($('#<%=txtShipDate.ClientID %>').val());
            $('#<%=lblConfirmEmail.ClientID %>').html($('#<%=txtEmail.ClientID %>').val());
        }

        function onFinishCallback(obj) {
            if(validateStep(1) && validateStep(2)){
                $('#<%= btnSubmit.ClientID %>').click();
            }
        }

        function initUI(step, enableFinish, enableAllStep){
            if(enableFinish == undefined || enableFinish == null)
                enableFinish = false;
            if(step == undefined || step == null)
                step = 0;
            if(enableAllStep == undefined || enableAllStep == null)
                enableAllStep = true;

            $("#<%=txtShipDate.ClientID  %>").datepicker({ dateFormat: 'dd M yy' });
            $('#wizard').smartWizard({ onLeaveStep: leaveAStepCallback, onFinish: onFinishCallback, selected: step, enableFinishButton: enableFinish, enableAllSteps: enableAllStep});
        }

        $(document).ready(function () {
            initUI(0);
        });

        function checkout(key, shippingcost){
            document.getElementById("shipping_1").value = shippingcost;
            document.getElementById("return").value = document.getElementById("return").value + key;   
            document.getElementById("address1").value =  document.getElementById("<%= txtShipTo.ClientID %>").value;
            document.getElementById("first_name").value =  document.getElementById("<%= txtName.ClientID %>").value;
            document.getElementById("<%= btnCheckOut.ClientID %>").click();
        }

    </script>

    <input type='hidden' name="currency_code" value="AUD" />
    <input type='hidden' name="cmd" value="_cart" />
    <input type='hidden' name="upload" value="1" />
    <input type='hidden' name="business" value='<%= POSSystem.BLL.Utilities.GetConfigAppSetting("PayPalAccount") %>' />
    <input type='hidden' name='return' id='return'  value="<%= GetThankYouURL() %>" />
    <input type='hidden' name='cancel_return' value='http://www.afyo.com.au' />
    <input type='hidden' id='shipping_1' name='shipping_1' value='<%= POSSystem.BLL.SystemVariables.SysVars.ShippingCost.ToString() %>' />
    <input type='hidden' name='address1' id='address1' value='' />
    <input type='hidden' name='first_name' id='first_name' value='' />
    
    <div style='height: 20px'>
        &nbsp;
    </div>
    <asp:UpdatePanel ID="updateCart" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Button ID="btnCheckOut" runat="server" Style="display: none" />
            <asp:Button ID="btnSubmit" runat="server" Style='display: none' OnClick="btnSubmit_OnClick" />
            <div id="wizard" class="swMain">
                <ul>
                    <li><a href="#step-1" class="selected">
                        <label class="stepNumber">
                            1</label>
                        <span class="stepDesc">Step 1<br />
                            <small>Cart</small> </span></a></li>
                    <li><a href="#step-2">
                        <label class="stepNumber">
                            2</label>
                        <span class="stepDesc">Step 2<br />
                            <small>Delivery</small> </span></a></li>
                    <li><a href="#step-3">
                        <label class="stepNumber">
                            3</label>
                        <span class="stepDesc">Step 3<br />
                            <small>Confirmation</small> </span></a></li>
                </ul>
                <div id="step-1" class="cart-step">
                    <h2>
                        Shopping Cart</h2>
                    <p class='subtitle'>
                        Manage the item you want to purchase</p>
                    <cc:ShoppingCart ID="cart" runat="server" OnCartChanged="cart_OnCartChanged"></cc:ShoppingCart>
                </div>
                <div id="step-2" class="cart-step">
                    <h2>
                        Delivery Information</h2>
                    <p class='subtitle'>
                        Provide the information or help us to serve you better by logging into the website.
                        If you are new to us, you can register <a href="Register.aspx">here</a>.</p>
                    <div class='cart-form'>
                        <table cellpadding="5" style='margin: auto' cellspacing="5">
                            <tr>
                                <td>
                                    Name
                                    <label class='required'>*</label>
                                </td>
                                <td>
                                    <asp:TextBox ID='txtName' runat="server" class='tb7'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Phone(Tel.)
                                    <label class='required'>*</label>
                                </td>
                                <td>
                                    <asp:TextBox ID='txtPhone' runat="server" class='tb7'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Address
                                    <label class='required'>*</label>
                                </td>
                                <td>
                                    <asp:TextBox ID='txtAddress' runat="server" class='tb7'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Ship To
                                    <label class='required'>*</label>
                                </td>
                                <td>
                                    <asp:TextBox ID='txtShipTo' runat="server" class='tb7'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Ship Time
                                </td>
                                <td>
                                    <asp:TextBox ID='txtShipDate' runat="server" class='tb7'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Email
                                    <label class='required'>*</label>
                                </td>
                                <td>
                                    <asp:TextBox ID='txtEmail' runat="server" class='tb7'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Voucher
                                </td>
                                <td>
                                    <asp:TextBox ID='txtVoucherCode' OnTextChanged="txtVoucher_OnTextChanged" AutoPostBack="true"
                                        runat="server" class='tb150'></asp:TextBox>
                                    <asp:Label ID="lblVoucher" runat="server" Style='color: red; font-weight: bold'></asp:Label>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div id="step-3" class="cart-step">
                    <h2>
                        Order Confirmation</h2>
                    <p class='subtitle'>
                        Click Finish to submit your order</p>
                    <table style='border: 1px solid #cccccc; font-size: 13px; text-transform: none; line-height: 1.5em'
                        width="100%">
                        <tr>
                            <td align="left" valign="top">
                                <asp:Label ID="lblCompanyName" runat="server"></asp:Label><br />
                                <asp:Label ID="lblCompanyAddress" runat="server"></asp:Label><br />
                                <asp:Label ID="lblCompanyPhone" runat="server"></asp:Label><br />
                            </td>
                            <td align="right" valign="top">
                                <asp:Label Font-Bold="true" ID="lblCustomerOrder" runat="server" Text="CUSTOMER ORDER"></asp:Label><br />
                                <asp:Label ID="lblDate" runat="server"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td style='border-top: 1px dotted #cccccc; padding-top: 15px' colspan='2'>
                                <table width="100%">
                                    <tr>
                                        <td align="left" style='width: 80px; vertical-align: top'>
                                            <asp:Label runat="server" Font-Bold="true" Text="Customer"></asp:Label>
                                        </td>
                                        <td align="left" style='width: 250px; vertical-align: top'>
                                            <asp:Label ID="lblConfirmName" runat="server" Text=""></asp:Label>
                                        </td>
                                        <td align="left" style='width: 80px; vertical-align: top'>
                                            <asp:Label ID="Label1" runat="server" Font-Bold="true" Text="Phone"></asp:Label>
                                        </td>
                                        <td align="left">
                                            <asp:Label ID="lblConfirmPhone" runat="server" Text=""></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="left" valign="top">
                                            <asp:Label ID="Label5" runat="server" Font-Bold="true" Text="Email"></asp:Label>
                                        </td>
                                        <td align="left" valign="top">
                                            <asp:Label ID="lblConfirmEmail" runat="server" Text=""></asp:Label>
                                        </td>
                                        <td align="left" valign="top">
                                            <asp:Label ID="Label2" runat="server" Font-Bold="true" Text="Address"></asp:Label>
                                        </td>
                                        <td align="left" valign="top">
                                            <asp:Label ID="lblConfirmAddress" runat="server" Text=""></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="left" valign="top">
                                            <asp:Label ID="Label3" runat="server" Font-Bold="true" Text="Ship To"></asp:Label>
                                        </td>
                                        <td align="left" valign="top">
                                            <asp:Label ID="lblConfirmShipTo" runat="server" Text=""></asp:Label>
                                        </td>
                                        <td align="left" valign="top">
                                            <asp:Label ID="Label4" runat="server" Font-Bold="true" Text="Ship Date"></asp:Label>
                                        </td>
                                        <td align="left" valign="top">
                                            <asp:Label ID="lblConfirmShipDate" runat="server" Text=""></asp:Label>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan='2' style='padding-top: 15px'>
                                <cc:ShoppingCart ID="confirmCart" runat="server" />
                                <div style="float:right">
                                    <asp:Literal Visible="false" ID="lblDiscount" runat="server"></asp:Literal><br />
                                    <asp:Literal ID="lblShipping" runat="server"></asp:Literal><br />
                                    <asp:Literal ID="lblTotalAmount" runat="server"></asp:Literal>
                                </div>
                                <div style='clear:both'>&nbsp</div>
                                <div style='margin-top:10px; text-align:justify; font-size:10px; clear:both'>
                                    Shopping at afyo.com.au is all about maximising your savings. So if you buy more than one item, your shipping costs for the 2nd, 3rd or subsequent items is at 50% less than the first item.
                                    <br />How can you benefit from Combine and Save? Simply order any two or more items at a time and you instantly benefit by paying substantially lower shipping charges on the 2nd, 3rd or subsequent items.
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
